//package com.itheima.service;
//
//import com.aliyun.oss.OSS;
//import com.aliyun.oss.OSSClient;
//import com.itheima.common.constant.RedisConstant;
//import com.itheima.common.utils.AliOssUtil;
//import com.itheima.service.impl.RedisService;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.data.redis.core.StringRedisTemplate;
//import org.springframework.scheduling.annotation.Scheduled;
//import org.springframework.stereotype.Component;
//import org.springframework.stereotype.Service;
//
//import java.util.Set;
//@Component
//public class ImageCleanupTask {
//
//    @Autowired
//    private RedisService redisService;
//
//    @Autowired
//    private AliOssUtil aliOssUtil;
//    private static final String BUCKET_NAME = "your-bucket-name";
//
//    // 每天凌晨3点执行
//    @Scheduled(cron = "0 0 3 * * ?")
//    public void cleanupOrphanImages() {
//        // 计算差集：临时集合有而数据库集合没有的图片
//        Set<String> orphanImages = redisService.difference(
//                RedisConstant.SETMEAL_PIC_RESOURCES,
//                RedisConstant.SETMEAL_PIC_DB_RESOURCES
//        );
//
//        // 删除OSS中的垃圾图片
//        for (String imageName : orphanImages) {
//            aliOssUtil.delete(BUCKET_NAME, objectName);
//            // 从Redis临时集合中移除
//            redisService.removeFromSet(RedisConstant.SETMEAL_PIC_RESOURCES, imageName);
//        }
//
//        // 可以添加日志记录删除了多少图片
//    }
//}
//}